//
//  SLWebView.h
//  SLWebView
//
//  Created by S_LINE on 2020/6/23.
//  Copyright © 2020 S_LINE. All rights reserved.
//

#import <UIKit/UIKit.h>

#import <WebKit/WebKit.h>

NS_ASSUME_NONNULL_BEGIN

@class SLWebView;
@protocol SLWebViewNavigationDelegate <NSObject>

@optional
/// 自定义
- (BOOL)webView:(SLWebView *)webviewContainer didStartLoadingURL:(NSURL *)url isLinkActivate:(BOOL)isLinkActivate;
- (void)webView:(SLWebView *)webviewContainer didFinishLoadingURL:(NSURL *)url;
- (void)webView:(SLWebView *)webviewContainer didFailToLoadURL:(NSURL *)url error:(NSError *)error;

@end

@protocol SLWebViewUIDelegate <NSObject>

@optional
/// 自定义
- (void)webView:(SLWebView *)webviewContainer runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler;
- (void)webView:(SLWebView *)webviewContainer runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler;
- (void)webView:(SLWebView *)webviewContainer runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(NSString * _Nullable))completionHandler;

@end

@interface SLWebView : UIView

@property (nonatomic, strong, nullable) WKWebView *wkWebView;
/*! @abstract The web view's navigation delegate. */
@property (nullable, nonatomic, weak) id <SLWebViewNavigationDelegate> navigationDelegate;
/*! @abstract The web view's user interface delegate. */
@property (nullable, nonatomic, weak) id <SLWebViewUIDelegate> UIDelegate;

- (instancetype)initWithConfiguration:(WKWebViewConfiguration *)configuration;

- (void)loadRequest:(NSURLRequest *)request;
- (void)loadURL:(NSURL *)URL;
- (void)loadURLString:(NSString *)URLString;
- (void)loadHTMLString:(NSString *)HTMLString;
//WkWebView reload
- (void)reload;
//WkWebView back
- (BOOL)back;
- (void)stopLoad;

@end

NS_ASSUME_NONNULL_END
